class Resource::Item < ActiveRecord::Base
  set_table_name "resource_items"

  def type_name
    type_nr = (self.doc_type.nil?) ? 0 : self.doc_type.to_i
    case type_nr
    when 0
      return nil
    when 1
      return 'paper'
    when 2
      return 'book'
    when 3
      return 'popular'
    when 4
      return 'blog'
    when 5
      return 'news'
    end
  end
  
  def summary
    self.abstract.split[0..(30-1)].join(" ") + (self.abstract.split.size > 30 ? "..." : "")
  end

  def source_name
    name = self.source.downcase
    name = (name.include? 'http://') ? name.sub('http://', '') : name
    name = name.split('/')
    name = name[0].to_s
    return name
  end

  def source_uri
    uri = self.source.downcase
    uri = (uri.include? 'http://') ? uri : "http://#{uri}"
    return uri
  end
end
